package com.oneinlet.controller;

import com.oneinlet.component.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;


/**
 * Created by WangZiHe on 2017/11/5
 * QQ/WeChat:648830605
 * QQ-Group:368512253
 * Blog:www.520code.net
 * Github:https://github.com/yancheng199287
 */
public class BaseController {

    public Logger logger = LoggerFactory.getLogger(this.getClass());
    public HashMap<Object, Object> data;
    public HttpServletRequest request;
    public HttpServletResponse response;

    @ModelAttribute
    public void setReqAndRes(HttpServletRequest request, HttpServletResponse response) {
        this.request = request;
        this.response = response;
        if (data != null) data.clear();
    }

    public JsonResult.Result setOKResult() {
        return setOKResult(null);
    }

    public JsonResult.Result setOKResult(Object data) {
        return JsonResult.getSuccessResult(data);
    }

    public JsonResult.Result setFailedResult(String message) {
        return JsonResult.getFailResult(message);
    }

}
